// Copyright (C) 2022 Linlexiao
#include "exportproblemdialog.h"

#include <QApplication>
#include <QByteArray>
#include <QClipboard>
#include <QDebug>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>

ExportProblemDialog::ExportProblemDialog(const QString &s) {
    resize(800, 600);
    base64encode = QString(s.toUtf8().toBase64());
    setStyleSheet("*{font:16pt 微软雅黑}");
    setWindowTitle("导出问题");
    setWindowIcon(QIcon(":/src/img/icon.png"));
    auto mainLayout = new QVBoxLayout();
    auto lb = new QLabel("问题代码:", this);
    mainLayout->addWidget(lb);
    auto edit = new QTextEdit(this);
    edit->setPlainText(base64encode);
    edit->setReadOnly(true);
    edit->selectAll();
    auto btn1 = new QPushButton("取消", this);
    connect(btn1, &QPushButton::clicked, this, &QDialog::reject);
    auto btn2 = new QPushButton("复制到剪贴板", this);
    btn2->setFocus();
    btn2->setDefault(1);
    connect(btn2, &QPushButton::clicked, this, &ExportProblemDialog::onCopy);
    auto layout2 = new QHBoxLayout();
    mainLayout->addWidget(edit);
    layout2->addWidget(btn1);
    layout2->addWidget(btn2);
    mainLayout->addLayout(layout2);
    setLayout(mainLayout);
}

void ExportProblemDialog::onCopy() {
    QApplication::clipboard()->setText(base64encode);
    accept();
}
